<template>
	<view style="padding:50rpx;">
		<view style="height:150rpx;"></view>
		<view class="gui-flex gui-rows gui-justify-content-center">
			<!-- <text class="login-logo gui-icons gui-color-white gui-block-text gui-border-box gui-bg-black gui-box-shadow gui-box">&#xe620;</text> -->
			<image class="login-logo" src="@/static/activity/apply/logo.png" mode=""></image>
		</view>
		
		<view class="gui-text-center" v-if="is_admin">
			<text class="gui-color-blue gui-h4">管理员登录</text>
		</view>
			
		<view style="margin-top:80rpx;">
			<form @submit="submit">
				<view>
					<text class="gui-text-small gui-color-gray">账户</text>
				</view>
				
				<view v-if="login_type == 1" class="gui-border-b">
					<input type="text" class="gui-form-input" 
					name="phone" placeholder="账户" value="" />
				</view>
				
				<view v-else class="gui-border-b">
					<input type="text" class="gui-form-input" 
					name="userName" placeholder="厂牌号" value="" />
				</view>
				
				<view class="gui-margin-top">
					<text class="gui-text-small gui-color-gray">密码</text>
				</view>
				<view class="gui-border-b">
					<input type="password" class="gui-form-input" name="password" placeholder="密码" value="" />
				</view>
				<view class="gui-margin-top gui-flex gui-rows gui-space-between" hover-class="gui-tap">
					<text class="gui-text gui-color-gray gui-block-text" @tap="forgetPwd">忘记密码</text>
					<text v-if="login_type == 1" class="gui-text gui-color-gray gui-block-text gui-text-right" @tap="login_type = !login_type">厂牌号登录</text>
					<text v-else class="gui-text gui-color-gray gui-block-text gui-text-right" @tap="login_type = !login_type">手机号登录</text>
					<!-- <navigator class="gui-text gui-color-gray gui-block-text gui-text-right" url="../reg/reg" >注册</navigator> -->
				</view>
				<view style="margin-top:38rpx;">
					<button type="default" class="gui-button gui-bg-black" formType="submit" 
					style="border-radius:50rpx;">
						<text class="gui-color-white gui-button-text">登 录</text>
					</button>
				</view>
			</form>
		</view>
		
		<!-- <view class="gui-flex gui-rows gui-nowrap gui-align-items-center" style="margin-top:80rpx;">
			<view class="gui-title-line"></view>
			<text class="gui-primary-color gui-h6" style="padding-left:50rpx; padding-right:50rpx;">其他方式登录</text>
			<view class="gui-title-line"></view>
		</view>
		<view class="gui-flex gui-rows gui-nowrap gui-justify-content-center gui-margin-top">
			<view class="other-login-icons" hover-class="gui-tap">
				<text class="other-login-icons gui-icons">&#xe63e;</text>
			</view>
			<view class="other-login-icons" hover-class="gui-tap">
				<text class="other-login-icons gui-icons">&#xe6cd;</text>
			</view>
		</view> -->
	</view>
</template>
<script>
var graceChecker = require("@/Grace6/js/checker.js");
export default {
	data() {
		return {
			login_type:1,
			is_admin:false,
		}
	},
	methods: {
		forgetPwd  : function () { console.log('请自行完善代码'); },
		loginbymsg : function () { console.log('请自行完善代码'); },
		submit : function(e){
			
			let self = this;
			// 表单数据
			var formData = e.detail.value;
			console.log(formData,'for');
			// 利用 graceUI 的表单验证工具进行验证
			//定义表单规则
			var rule = [
				// {name:"phone", checkType : "string", checkRule:"5,50", errorMsg:"登录账户输入有误"},
				{name:"password", checkType : "string", checkRule:"6,100", errorMsg:"登录密码至少6个字符"},
				
			];
			var checkRes = graceChecker.check(formData, rule);
			if(checkRes){
				//uni.showToast({title:"验证通过!", icon:"none"});
				
				// 根据项目需要完成数据验证工作
				let login_url = this.apiUrl+"/public/user_bh_login";
				if(self.login_type){
					login_url = this.apiUrl+"/public/login";
				}
				this.grace.post(login_url,formData,function(res){
					console.log(res);
					uni.showToast({title:res.msg, icon:"none"});
					if(res.code == 200){
						
						if(!res.data.avatar){//默认头像
							res.data.avatar = "http://boyaltd.oss-cn-hangzhou.aliyuncs.com/2022-09/30/URYwmphpTzYSFy1664527982220930.png";
						}
						
						// if(res.data.wxid){//处理wxid
						// 	let w_arr = res.data.wxid.split("");
						// 	w_arr[4] = "*";w_arr[5] = "*";w_arr[6] = "*";w_arr[7] = "*";w_arr[8] = "*";w_arr[9] = "*";w_arr[14] = "*";w_arr[15] = "*";
						// 	res.data.wxid = w_arr.join("");
						// }
						// //处理phone
						// let p_arr = res.data.phone.toString().split("");
						// let uuid = "";
						// p_arr[4] = "*";p_arr[5] = "*";p_arr[6] = "*";p_arr[7] = "*";
						// res.data.phone = p_arr.join("");
						
						
						uni.setStorageSync("token",res.token);
						uni.setStorageSync("user",res.data);
						if(res.data.type == 9){
							uni.reLaunch({
								url:"../user/admin/book_admin"
							});
						}else{
							// uni.reLaunch({
							// 	url:"../switchPages/index"
							// });
							uni.reLaunch({
								url:"../apply/index2"
							});
						}
					}else{
						uni.showToast({title:res.msg, icon:"none"});
					}
				});
			}else{
				uni.showToast({ title:graceChecker.error, icon: "none" });
			}
		},
	}
}
</script>
<style>
.login-logo{width:180rpx; height:180rpx; font-size:80rpx; text-align:center; line-height:120rpx; padding:30rpx; border-radius:18rpx;}
.other-login-icons{width:88rpx; height:88rpx; text-align:center; font-size:70rpx; margin:20rpx;}
</style>